from django.db import models
# Create your models here.
#  书籍的模型类
class BookInfo(models.Model):
    name = models.CharField(max_length=20,verbose_name='图书名称')
    pub_date = models.DateField(null=True,verbose_name='发布日期')
    readcount = models.IntegerField(default=0,verbose_name='阅读量')
    commentcount = models.IntegerField(default=0,verbose_name='评论量')
    is_delete = models.BooleanField(default=False,verbose_name='逻辑删除')
    class Meta:
        # 表的名字
        db_table = 'bookinfo'
        # 界面显示的表的名称
        verbose_name = '书籍表'
        # 界面显示的表的名称的复数
        verbose_name_plural = verbose_name

    def __str__(self):
        return  self.name




#  人物 模型类
class PeopleInfo(models.Model):
    GENDER_CHOICES = (
        (0,'女'),
        (1,'男')
    )
    # 人物名称 字符串类型
    name = models.CharField(max_length=20,verbose_name='人物姓名')
    #  人物性别  布尔类型：False True
    gender = models.SmallIntegerField(choices=GENDER_CHOICES,default=0,verbose_name='性别')
    # 描述信息 字符串类型
    description = models.CharField(max_length=200,null=True,verbose_name='描述信息')
    is_delete = models.BooleanField(default=False,verbose_name='逻辑删除')

    #  外键约束： 书籍BookInfo
    book = models.ForeignKey(BookInfo, on_delete=models.CASCADE,verbose_name='图书')
    class Meta:
        db_table = 'peopleinfo'
        verbose_name = '人物表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return  self.name

